package com.stars.easyms.redis.holder;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * <p>className: RedisInfoHolder</p>
 * <p>description: Redis信息存放类</p>
 *
 * @author guoguifang
 * @version 1.2.1
 * @date 2019-03-20 15:43
 */
public final class RedisInfoHolder {

    private static final Map<String, Map<String, Set<RedisMethodInfo>>> REDIS_INFO_HOLDER = new ConcurrentHashMap<>(64);

    private static final List<RedisMethodInfo> REDIS_SCRIPT_INFO_HOLDER = new CopyOnWriteArrayList<>();

    public static void putRedisMethod(String prefix, String group, RedisMethodInfo redisMethodInfo) {
        REDIS_INFO_HOLDER.computeIfAbsent(prefix, key -> new TreeMap<>()).computeIfAbsent(group, key -> new HashSet<>()).add(redisMethodInfo);
    }

    public static void putScriptRedisMethod(RedisMethodInfo redisMethodInfo) {
        REDIS_SCRIPT_INFO_HOLDER.add(redisMethodInfo);
    }

    public static Map<String, Map<String, Set<RedisMethodInfo>>> getRedisMethodInfo() {
        return REDIS_INFO_HOLDER;
    }

    public static List<RedisMethodInfo> getRedisScriptMethodInfo() {
        return REDIS_SCRIPT_INFO_HOLDER;
    }

    private RedisInfoHolder() {}
}